/* 二级联动处理 */
function relaFix(param){
	
	var before = param.before;
	var parent = param.parent;
	var child = param.child;
	var method = param.method;
	var after = param.after;
			
	$("#"+parent).change(function(e) {
		
		//前置方法
		if(before){
			eval(before+"();");
		}
		
		if(method){
			
			//主体方法
			var mc_g = document.getElementById(parent).value;
			
			var sendSet = new Yacon.data.DataSet();
			sendSet.setWhereField(parent,mc_g);
			sendSet.switchMessage(method);
			
			var option = "<option value=''> </option>";
			
			while(sendSet.next()){
				option += "<option value='"+sendSet.getFieldValue("value")+"'>"+sendSet.getFieldValue("text")+"</option>";
			} 
				
			$("#"+child+" option").remove();
			$("#"+child).append(option);
			
		}
			
		//后置方法
		if(after){
			eval(after+"();");
		}
		
	});
	
}

/* 基本二级联动 */
function rela(parent,child,method){
	$("#"+parent).change(function(e) {
		var mc_g = document.getElementById(parent).value;
		
		var sendSet = new Yacon.data.DataSet();
		sendSet.setWhereField(parent,mc_g);
		sendSet.switchMessage(method);
		
		var option = "<option value=''> </option>";
		
		while(sendSet.next()){
			option += "<option value='"+sendSet.getFieldValue("value")+"'>"+sendSet.getFieldValue("text")+"</option>";
		} 
			
		$("#"+child+" option").remove();
		$("#"+child).append(option);
	});
}

/* 修改某个字段，给另一个字段赋值 */
function changeRela(parent,child,method){
	$("#"+parent).change(function(e) {
		var mc_p = document.getElementById(parent).value; 
		
		var sendSet = new Yacon.data.DataSet();
		sendSet.setWhereField(parent,mc_p);
		sendSet.switchMessage(method);
		
		if(sendSet.next()){
			document.getElementById(child).value = sendSet.getFieldValue(child);
		}else{
			document.getElementById(child).value = "";
		}
	});
}

/* 文本信息 */
function $Text(id,newText){
	if(newText){
		$("#"+id).text(newText);
	}
	return $("#"+id).text();
}

/* 下拉文本信息 */
function $DropText(id){
	return $("#"+id).find("option:selected").text();  
}

/* 值信息 */
function $Value(id,newValue){
	if(newValue){
		$("#"+id).val(newValue);
	}
	return $("#"+id).val();
}

/* 二级联动 初始装载 */
function ready(parent,child,method){
	
	var child_id = dataSet.getFieldValue(child);
	
	var mc_g = document.getElementById(parent).value;
	
	if(mc_g==undefined || mc_g==""){
		return;
	}
	
	var sendSet = new Yacon.data.DataSet();
	sendSet.setWhereField(parent,mc_g);
	sendSet.switchMessage(method);
	
	var option = "<option value=''> </option>";
	
	while(sendSet.next()){
		var value = sendSet.getFieldValue("value");
		var text = sendSet.getFieldValue("text");
		if(value == child_id){
			option += "<option value='"+value+"' selected>"+text+"</option>";
		}
		else{
			option += "<option value='"+value+"'>"+text+"</option>";
		}
	} 
		
	$("#"+child+" option").remove();
	$("#"+child).append(option);
}